<template>
    <div class="pd-30">
        <div class="flex">
            <div class=" center">
                <p>会议名称：</p>
                <el-input class="w-250" v-model="input" placeholder="请输入"></el-input>
            </div>
            <div class="flex ml-80">
                <el-button class="w-100" @click="chongzhi">重置</el-button>
                <el-button class="w-100" type="primary" plain @click="getUserList">搜索</el-button>
                <el-button class="w-100" type="primary" @click="addUser">新增</el-button>

            </div>
        </div>
        <div class="h-30"></div>
        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="id" label="编号" width="180">
            </el-table-column>
            <el-table-column prop="name" label="会议名称">
            </el-table-column>
            <el-table-column prop="joinNum" label="报名人数">
            </el-table-column>
            <el-table-column prop="address" label="地址">
            </el-table-column>
            <el-table-column prop="states" label="状态">
                <template #default="{ row }">
                    <p v-if="row.status == 1">正常</p>
                    <p v-else>禁用</p>
                </template>
            </el-table-column>
            <el-table-column prop="submitTime" label="创建时间">
            </el-table-column>
            <el-table-column label="操作" width="300">
                <template slot-scope="scope">
                    <el-button type="primary" plain size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                    <el-button size="mini" @click="getDetail(scope.row)">查看记录</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="flex mt-20">
            <div></div>
            <el-pagination :current-page="page" background layout="prev, pager, next" :total="total" @current-change="sizeChange">
            </el-pagination>
        </div>


        <el-dialog :visible.sync="dialogVisible" width="30%" :show-close="false">
            <span slot="title" class="dialog-footer">
                <h4 class="text-center">{{ type == 1 ? '增加' : '编辑' }}会议</h4>
            </span>
            <div class="plr-30">
                <div class="flex_l">
                    <div class="w-80">标签名称：</div>
                    <el-input class="w-350 ml-20" v-model="form.name" placeholder="请输入"></el-input>
                </div>
                <div class="flex_l mt-20">
                    <div class="w-80">报名人数：</div>
                    <el-input class="w-350 ml-20" v-model="form.joinNum" placeholder="请输入"></el-input>
                </div>
                <div class="flex_l mt-20">
                    <div class="w-80">会议时间：</div>
                    <el-date-picker v-model="form.time" class="w-350 ml-20" type="datetime" placeholder="选择会议时间">
                    </el-date-picker>
                </div>
                <div class="flex_l mt-20">
                    <div class="w-80">地址：</div>
                    <el-input class="w-350 ml-20" v-model="form.address" placeholder="请输入"></el-input>
                </div>
                <div class="flex_l mt-20">
                    <div class="w-80">简介：</div>
                    <el-input class="w-350 ml-20" v-model="form.content" size="small" type="textarea"
                        placeholder="请输入"></el-input>
                </div>
                <div class="flex_l mt-20">
                    <div class="w-80">备注：</div>
                    <el-input class="w-350 ml-20" v-model="form.beiZhu" size="small" type="textarea"
                        placeholder="请输入"></el-input>
                </div>
            </div>



            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="submit">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog :visible.sync="dialogVisible1" width="45%" :show-close="false">
            <span slot="title" class="dialog-footer">
                <h4 class="text-center">{{ selectName }}报名列表</h4>
            </span>
            <el-table :data="tableData1" border style="width: 100%">
                <el-table-column prop="userName" label="姓名" width="180">
                </el-table-column>
                <el-table-column prop="phone" label="手机号">
                </el-table-column>
                <el-table-column prop="joinNum" label="报名人数">
                </el-table-column>
                <el-table-column prop="beiZhu" label="备注">
                </el-table-column>
            </el-table>
            <div class="flex mt-20">
                <div></div>
                <el-pagination :current-page="page" background layout="prev, pager, next" :total="total1">
                </el-pagination>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible1 = false">取 消</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import { cusMeetingRecordList, cusMeetingList, cusMeetingAdd, cusMeetingEdit, cusMeetingRemove } from '@/api/configure.js'
export default {
    name: "Label",
    data() {
        return {
            dialogVisible: false,
            dialogVisible1: false,
            options1: [{
                value: '',
                label: '全部'
            }, {
                value: '1',
                label: '文创园地'
            }, {
                value: '2',
                label: '商品'
            }],
            input: '',
            tableData: [],
            page: 1,
            total: 0,
            upUrl: this.$upLoadUrl,
            type: '',
            form: {
                address: '',
                beiZhu: '',
                content: '',
                joinNum: '',
                name: '',
                pic: '1',
                time: ''
            },
            selectName: '',
            tableData1:[],
            page1:1,
            total1: 0,

        }
    },
    mounted() {
        this.getUserList()
    },
    methods: {
        sizeChange(e) {
            this.page = e
            this.getUserList()
        },
        getDetail(e) {
            this.dialogVisible1 = true
            this.selectName = e.name
            cusMeetingRecordList({
                pageNum:this.page1,
                pageSize:10,
                meetingId:e.id
            }).then(res=>{
                this.tableData1 = res.rows
                this.total1 = res.total
            })
        },
        addUser() {
            for (var i in this.form) {
                if (i != 'pic') {
                    this.form[i] = ''
                }
            }
            this.dialogVisible = true
            this.type = 1
        },
        getUserList() {
            cusMeetingList({
                pageNum: this.page,
                pageSize: 10,
                name: this.input
            }).then(res => {
                this.tableData = res.rows
                this.total = res.total
            })
        },
        submit() {
            var apiFunction = this.type == 1 ? cusMeetingAdd : cusMeetingEdit
            apiFunction(this.form).then(res => {
                if (res.code == 0) {
                    this.dialogVisible = false
                    this.getUserList()
                    this.$message({
                        message: this.type == 1 ? '添加成功' : '修改成功',
                        type: 'success'
                    });
                } else {
                    this.$message.error(res.msg || '失败');
                }
            })
        },


        chongzhi() {
            for (var i in this.form) {
                if (i != 'type') {
                    this.form[i] = ''
                }
            }
            this.getUserList()
        },

        handleEdit(e, type) {
            for (var i in this.form) {
                if (i != 'pic') {
                    this.form[i] = type[i]
                }
            }
            this.form.id = type.id
            this.dialogVisible = true
            this.type = 2
        },

        handleDelete(e, type) {
            this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

                cusMeetingRemove({ ids: type.id }).then(res => {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getUserList()
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
    }
}
</script>